package com.manager.plat.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;

import com.manager.plat.dao.IBalanceDao;
import com.manager.plat.dao.IRouterDao;
import com.manager.plat.vo.BalanceVo;
import com.manager.plat.vo.GatewayVo;
import com.manager.plat.vo.TermVo;
import com.manager.plat.vo.UserInfoVo;
import com.opensymphony.xwork2.ActionSupport;

public class BalancePartnerAction extends ActionSupport {
	/**
	 * 
	 */
	private static final long serialVersionUID = 8402810629373679678L;

	private static Logger logger = Logger.getLogger(BalancePartnerAction.class);
	
	private IBalanceDao balanceDao;			//结算信息数据接口
	private IRouterDao routerDao;			//路由信息数据接口
	private List<BalanceVo> balanceVoList;	//结算信息VO
	private List<GatewayVo> gatewayVoList;	//长号码信息列表
	private TermVo term;					//查询条件VO
	
	/**进入业务结算页面*/
	public String getRouter(){
		HttpServletRequest request = ServletActionContext.getRequest();
		UserInfoVo userInfoVo = (UserInfoVo) request.getAttribute("user");
		
		/**根据用户Id获得渠道下对应的长号码*/
		gatewayVoList = routerDao.getLowerGatewayByUserId(userInfoVo.getId());
		term = null;
		balanceVoList = null;
		
		return SUCCESS;
	}
	/**查询业务结算信息*/
	public String getRouterBalance(){
		HttpServletRequest request = ServletActionContext.getRequest();
		UserInfoVo userInfoVo = (UserInfoVo) request.getAttribute("user");
		/**获得用户ID*/
		int userId = userInfoVo.getId();
		/**获得网关ID*/
		int gateway_id = term.getGateway_id();
		/**获得开始时间*/
		String time_begin = term.getTime_begin();
		/**获得结束时间*/
		String time_end = term.getTime_end();
		logger.info(String.format("渠道查询收入条件[gateway_id=%d, time_begin=%s, time_end=%s]", gateway_id, time_begin, time_end));
		
		balanceVoList = balanceDao.getRouterBalancePartner(userId, gateway_id, time_begin, time_end);
		
		return SUCCESS;
	}
	
	public IBalanceDao getBalanceDao() {
		return balanceDao;
	}
	public void setBalanceDao(IBalanceDao balanceDao) {
		this.balanceDao = balanceDao;
	}
	public IRouterDao getRouterDao() {
		return routerDao;
	}
	public void setRouterDao(IRouterDao routerDao) {
		this.routerDao = routerDao;
	}
	public List<GatewayVo> getGatewayVoList() {
		return gatewayVoList;
	}
	public void setGatewayVoList(List<GatewayVo> gatewayVoList) {
		this.gatewayVoList = gatewayVoList;
	}
	public TermVo getTerm() {
		return term;
	}
	public void setTerm(TermVo term) {
		this.term = term;
	}
	public List<BalanceVo> getBalanceVoList() {
		return balanceVoList;
	}
	public void setBalanceVoList(List<BalanceVo> balanceVoList) {
		this.balanceVoList = balanceVoList;
	}
}
